cmake_minimum_required(VERSION 3.18)
project(unit_test)

set(test_libs PRIVATE GTest::gtest_main PRIVATE GTest::gmock PRIVATE spdlog::spdlog PRIVATE pthread)

function(add_unit_test name)
    foreach (item ${ARGN})
        list(APPEND test_source_list ${CMAKE_CURRENT_SOURCE_DIR}/../${item})
    endforeach ()

    add_executable(${name} ${name}.cpp ${test_source_list} ${CMAKE_CURRENT_SOURCE_DIR}/mock)
    target_link_libraries(${name} ${test_libs})
    target_include_directories(${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src/include)
    add_test(NAME ${name} COMMAND ${name})
endfunction()

add_unit_test(my_test)
add_unit_test(task_queue_test src/task_queue.cpp)
add_unit_test(STL_thread_test src/STL_thread.cpp src/task_queue.cpp)
add_unit_test(thread_manage_test src/thread_manage.cpp src/task_queue.cpp src/STL_thread.cpp)
add_unit_test(thread_pool_test src/thread_pool.cpp src/thread_manage.cpp src/task_queue.cpp src/STL_thread.cpp)
